package com.example.sharding.demo.controller;

import com.example.sharding.demo.model.BaseEntity;
import com.example.sharding.demo.model.table.User;
import com.example.sharding.demo.service.IUserService;
import com.example.sharding.demo.utils.KeyGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by liulanhua on 2018/9/25.
 */
@RestController
public class IndexController {

    @Autowired
    IUserService userService;

    @GetMapping(value = "/insertUser")
    public ModelAndView insertUser(User user, ModelAndView mv) {
        int id = (int)(Math.random() * 1000000000d);
        String userId = KeyGenerator.getUUID();
        user.setId(id);
        user.setUserId(userId);
        int i = userService.insertUser(new BaseEntity<User>(user));
        mv.setViewName("index");
        mv.addObject("record", "Hello, Please login !");
        return mv;
    }


}
